package cn.lotusnut.rabbitmqboot.controller;

import cn.lotusnut.rabbitmqboot.kill.KillProvider;
import cn.lotusnut.rabbitmqboot.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author JiangMing Zhou
 * @Date 2022/12/2 15:50
 * @Version 1.8
 */
@Slf4j
@RestController
@RequestMapping("/kill")
public class KillController {
    @Resource
    private KillProvider killProvider;
    @Resource
    private RedisUtil redisUtil;

    @GetMapping("/start/{user}")
    public String start(@PathVariable("user") String user){
        Integer stock = (Integer) redisUtil.get("stock");
        if (stock>0){
            killProvider.sendMessage(user);
            return "正在为你秒杀";
        }else {
            return "秒杀商品已抢光";
        }
    }

}
